import {RequestParam,HttpRequest} from '@/utils/http'

/**
 * 购物车服务
 */
export const CartService = {
	listCart: function() {
		const request = new RequestParam();
		request.url = "/api/cart/list.do";
		return HttpRequest(request);
	},
	addCart:function(data){
		const request = new RequestParam();
		request.url = "/api/cart/add.do";
		request.method="POST";
		request.param=data;
		return HttpRequest(request);
	},
	directBuy:function(){
		const request = new RequestParam();
		request.url = "/api/cart/add.do";
		request.method="POST";
		request.param=data;
		return HttpRequest(request);
	},
	delCart:function(productId,sn){
		const request = new RequestParam();
		request.url = "/api/cart/remove.do";
		request.param={productId:productId,sn:sn};
		return HttpRequest(request);
	},
	loadProductCountFromCart:function(){
		const request = new RequestParam();
		request.url = "/api/cart/count.do";
		return HttpRequest(request);
	},
	// 计算订单的运费
	getOrderFreight:function(bookingOrder){
		const request = new RequestParam();
		request.url = "/api/cart/calculate/freight.do";
		request.param=bookingOrder;
		request.method="POST";
		return HttpRequest(request);
	},
	// 计算订单优惠卷折扣
	getOrderCouponDiscount:function(bookingOrder){
		const request = new RequestParam();
		request.url = "/api/cart/calculate/discount.do";
		request.param=bookingOrder;
		request.method="POST";
		return HttpRequest(request);
	}
}

/**
 * 订单服务
 */
export const OrderService = {
	// 提交订单
	bookingOrder:function(bookingOrder){
		const request = new RequestParam();
		request.url = "/api/order/booking.do";
		request.param=bookingOrder;
		request.method="POST";
		return HttpRequest(request);
	},
	// 订单列表
	list:function(status){
		const request = new RequestParam();
		request.url = "/api/order/list.do";
		request.param={status:status};
		return HttpRequest(request);
	},
	// 订单详情
	detail:function(orderNo){
		const request = new RequestParam();
		request.url = "/api/order/detail.do";
		request.param={orderNo:orderNo};
		return HttpRequest(request);
	},
	// 取消订单
	cancelOrder:function(orderNo){
		const request = new RequestParam();
		request.url = "/api/order/cancel.do";
		request.param={orderNo:orderNo};
		return HttpRequest(request);
	},
	// 发起订单支付
	payOrder:function(orderNo){
		const request = new RequestParam();
		request.url = "/api/order/minipro/pay.do";
		request.param={orderNo:orderNo};
		return HttpRequest(request);
	},
	// 订单微信端交易状态
	getOrderTradeStatus(orderNo){
		const request = new RequestParam();
		request.url = "/api/order/query/trade/status.do";
		request.param={orderNo:orderNo};
		return HttpRequest(request);
	},
	// 买家确认收货
	confirmReceive(orderNo){
		const request = new RequestParam();
		request.url = "/api/order/confirm/receive.do";
		request.param={orderNo:orderNo};
		return HttpRequest(request);
	},
	// 订单支付相关消息模板
	payTemplates(){
		const request = new RequestParam();
		request.url = "/api/wechat/template/pay.do";
		return HttpRequest(request);
	},
	// 取消订单相关消息模板
	cancelTemplates(){
		const request = new RequestParam();
		request.url = "/api/wechat/template/cancel.do";
		return HttpRequest(request);
	}
}